<?php
echo form_open('customers/save/'.$person_info->person_id,array('id'=>'customer_form'));
?>
<div id="required_fields_message"><?php echo lang('common_fields_required_message'); ?></div>
<ul id="error_message_box"></ul>
<fieldset id="customer_basic_info">
<legend><?php echo lang("customers_basic_information"); ?></legend>


<div class="field_row clearfix">
<?php echo form_label(lang('common_title').':', 'title', array('class'=>'required')); ?>
	<div class='form_field'>
	<?php echo form_dropdown('title', array(''  => '', 'Mr.' => 'Mr.', 'Ms.' => 'Ms.', 'Mrs.' => 'Mrs.'), $person_info->title);?>
	</div>
</div>

<div class="field_row clearfix">	
<?php echo form_label(lang('common_nric').':', 'nric',array('class'=>'required')); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'nric',
		'id'=>'nric',
		'value'=>$person_info->nric)
	);?>
	</div>
</div>

<div class="field_row clearfix">	
<?php echo form_label(lang('common_first_name').':', 'first_name',array('class'=>'required')); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'first_name',
		'id'=>'first_name',
		'value'=>$person_info->first_name)
	);?>
	</div>
</div>

<div class="field_row clearfix">	
<?php echo form_label(lang('common_last_name').':', 'last_name',array('class'=>'required')); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'last_name',
		'id'=>'last_name',
		'value'=>$person_info->last_name)
	);?>
	</div>
</div>

<div class="field_row clearfix">	
<?php echo form_label(lang('common_email').':', 'email'); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'email',
		'id'=>'email',
		'value'=>$person_info->email)
	);?>
	</div>
</div>

<div class="field_row clearfix">	
<?php echo form_label(lang('common_phone_number').':', 'phone_number'); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'phone_number',
		'id'=>'phone_number',
		'value'=>$person_info->phone_number));?>
	</div>
</div>

<div class="field_row clearfix">	
<?php echo form_label(lang('common_address_1').':', 'address_1'); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'address_1',
		'id'=>'address_1',
		'value'=>$person_info->address_1));?>
	</div>
</div>

<div class="field_row clearfix">	
<?php echo form_label(lang('common_address_2').':', 'address_2'); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'address_2',
		'id'=>'address_2',
		'value'=>$person_info->address_2));?>
	</div>
</div>

<div class="field_row clearfix" style="display:none;">	
<?php echo form_label(lang('common_city').':', 'city'); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'city',
		'id'=>'city',
		'value'=>$person_info->city));?>
	</div>
</div>

<div class="field_row clearfix" style="display:none;">	
<?php echo form_label(lang('common_state').':', 'state'); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'state',
		'id'=>'state',
		'value'=>$person_info->state));?>
	</div>
</div>

<div class="field_row clearfix">	
<?php echo form_label(lang('common_zip').':', 'zip'); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'zip',
		'id'=>'zip',
		'value'=>$person_info->zip));?>
	</div>
</div>

<div class="field_row clearfix">	
<?php echo form_label(lang('common_country').':', 'country'); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'country',
		'id'=>'country',
		'value'=>$person_info->country));?>
	</div>
</div>

<?php
if ($this->config->item('mailchimp_api_key'))
{
?>
<div class="field_row clearfix">
	<div class="column">	
		<?php echo form_label(lang('common_mailing_lists').':', 'mailchimp_mailing_lists'); ?>
	</div>
	
    <div class="column">
		<ul style="list-style: none;">
	<?php 
	foreach(get_all_mailchimps_lists() as $list)
	{
		echo '<li>';
		echo form_checkbox(array('name'=> 'mailing_lists[]',
		'id' => $list['id'],
		'value' => $list['id'],
		'checked' => email_subscribed_to_list($person_info->email, $list['id']),
		'label'	=> $list['id']));
		echo form_label($list['name'], $list['id'], array('style' => 'float: none;'));
		echo '</li>';
	}
	?>
	</ul>
	</div>
	<div class="cleared"></div>
</div>
<?php
}
?>

<div class="field_row clearfix">	
<?php echo form_label(lang('config_company').':', 'company_name'); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'company_name',
		'id'=>'customer_company_name',
		'value'=>$person_info->company_name)
	);?>
	</div>
</div>

<div class="field_row clearfix">
<?php echo form_label(lang('common_designation').':', 'designation'); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'designation',
		'id'=>'designation',
		'value'=>$person_info->designation)
	);?>
	</div>
</div>

<div class="field_row clearfix">
<?php echo form_label(lang('common_nationality').':', 'nationality'); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'nationality',
		'id'=>'nationality',
		'value'=>$person_info->nationality)
	);?>
	</div>
</div>

<div class="field_row clearfix">
<?php echo form_label(lang('common_birthday').':', 'birthday'); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'birthday',
		'id'=>'birthday',
		'value'=>$person_info->birthday)
	);?>
	(yyyy-mm-dd)
	</div>
</div>

<div class="field_row clearfix">
<?php echo form_label(lang('common_preferred_contact').':', 'preferred_contact'); ?>
	<div class='form_field'>
	<?php echo form_dropdown('preferred_contact', array(''  => '', '' => '', 'Email' => 'Email', 'Phone' => 'Phone', 'Letter' => 'Letter'), $person_info->preferred_contact);?>
	</div>
</div>

<div class="field_row clearfix">
<?php echo form_label(lang('common_store').':', 'store'); ?>
	<div class='form_field'>
	<?php echo $person_info->store;?>
	<?php echo form_hidden('store', $person_info->store);?>
	</div>
</div>

<div class="field_row clearfix">
<?php echo form_label(lang('common_create_date').':', 'create_date'); ?>
	<div class='form_field'>
	<?php echo $person_info->create_date;?>
	<?php echo form_hidden('create_date', $person_info->create_date);?>
	</div>
</div>

<div class="field_row clearfix">
<?php echo form_label(lang('common_modify_date').':', 'modify_date'); ?>
	<div class='form_field'>
	<?php echo $person_info->modify_date;?>
	</div>
</div>

<div class="field_row clearfix">
<?php echo form_label(lang('common_modify_by').':', 'modify_by'); ?>
	<div class='form_field'>
	<?php echo $person_info->modify_by;?>
	<?php echo form_hidden('modify_by', 'Test');?>
	</div>
</div>

<div class="field_row clearfix" style="display:none;">	
<?php echo form_label(lang('customers_account_number').':', 'account_number'); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'account_number',
		'id'=>'account_number',
		'value'=>$person_info->account_number)
	);?>
	</div>
</div>

<div class="field_row clearfix" style="display:none;">	
<?php echo form_label(lang('customers_taxable').':', 'taxable'); ?>
	<div class='form_field'>
	<?php echo form_checkbox('taxable', '1', $person_info->taxable == '' ? TRUE : (boolean)$person_info->taxable);?>
	</div>
</div>


<div class="field_row clearfix">	
<?php echo form_label(lang('common_comments').':', 'comments'); ?>
	<div class='form_field'>
	<?php echo form_textarea(array(
		'name'=>'comments',
		'id'=>'comments',
		'value'=>$person_info->comments,
		'rows'=>'5',
		'cols'=>'17')		
	);?>
	</div>
</div>

<?php
echo form_submit(array(
	'name'=>'submit',
	'id'=>'submit',
	'value'=>lang('common_submit'),
	'class'=>'submit_button float_right')
);
?>
</fieldset>
<?php 
echo form_close();
?>
<script type='text/javascript'>

//validation and submit handling
$(document).ready(function()
{
	var submitting = false;
	$('#customer_form').validate({
		submitHandler:function(form)
		{
			if (submitting) return;
			submitting = true;
			$(form).mask("<?php echo lang('common_wait'); ?>");
			$(form).ajaxSubmit({
			success:function(response)
			{
				tb_remove();
				post_person_form_submit(response);
				submitting = false;
			},
			dataType:'json'
		});

		},
		errorLabelContainer: "#error_message_box",
 		wrapper: "li",
		rules: 
		{
			first_name: "required",
			last_name: "required",
			nric: "required",
			title: "required",
    		email: "email"
   		},
		messages: 
		{
			title:  "<?php echo lang('common_title_required'); ?>",
			nric:  "<?php echo lang('common_nric_required'); ?>",
     		first_name: "<?php echo lang('common_first_name_required'); ?>",
     		last_name: "<?php echo lang('common_last_name_required'); ?>",
     		email: "<?php echo lang('common_email_invalid_format'); ?>"
		}
	});
	
	
	$( "#birthday" ).datePicker(
		{
			startDate: '<?php echo get_js_start_of_time_date(); ?>',
			endDate: (new Date()).asString()
		}
	);
});
});


</script>